Skip to content

refactor: message format and enable cache prompt#21

Merged
jjleng merged 1 commit intomainfrom
refactor-message-format
Apr 12, 2025
Merged

refactor: message format and enable cache prompt#21
jjleng merged 1 commit intomainfrom
refactor-message-format

Conversation

@jjleng
Copy link
Copy Markdown
Owner

@jjleng jjleng commented Apr 11, 2025

No description provided.

@jjleng jjleng requested a review from Copilot April 11, 2025 20:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

cp-agent/cp_agent/utils/message_formats.py:46

  • Removing the timestamp field from the Message TypedDict may impact parts of the system (e.g., chat history) that rely on message time information. Consider adding timestamp handling elsewhere if it is expected in production.
-    timestamp: str = field(default_factory=lambda: datetime.now().isoformat())

Comment on lines +79 to +83
message_content: list[MessagePart] = [create_text_block(content)]
if not IS_BEDROCK:
message_content = [create_text_block(content, "ephemeral")]
else:
message_content.append({"cachePoint": {"type": "default"}})
Copy link

Copilot AI Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caching implementation for assistant messages uses an ephemeral cache_control via create_text_block in one branch and appends a separate cachePoint block in the other branch. Consider standardizing the caching representation to avoid potential inconsistencies in message format.

Suggested change
message_content: list[MessagePart] = [create_text_block(content)]
if not IS_BEDROCK:
message_content = [create_text_block(content, "ephemeral")]
else:
message_content.append({"cachePoint": {"type": "default"}})
cache_type = "ephemeral" if not IS_BEDROCK else "default"
message_content: list[MessagePart] = [
create_text_block(content, cache_type),
{"cachePoint": {"type": cache_type}},
]

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bedrock and other vendors use different formats, sigh

@jjleng jjleng force-pushed the refactor-message-format branch from 58065d5 to 9819865 Compare April 12, 2025 06:49
@jjleng jjleng merged commit 5cecb28 into main Apr 12, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants